{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "def merge(path, fileName):\n",
    "    trainName = '../models/__models__/{}_{}.csv'.format(path, fileName)\n",
    "    testName = trainName.replace('train', 'test')\n",
    "    train = pd.read_csv(trainName)\n",
    "    test = pd.read_csv(testName)\n",
    "    data = pd.concat([train, test])\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\administrator\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2717: DtypeWarning: Columns (12,49) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5\n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4\n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4\n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5\n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('../input/data.csv')\n",
    "\n",
    "data_stacking = data[['Id', 'Score']].copy()\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  \n",
       "0       4.155004  \n",
       "1       4.446383  \n",
       "2       4.744894  \n",
       "3       4.616804  \n",
       "4       4.726782  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "models = [100, 101, 102]\n",
    "for model in models:\n",
    "    data_stacking = pd.merge(data_stacking, merge('lgbm_train', model), on = 'Id', how = 'left')\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "      <th>lc_label_1</th>\n",
       "      <th>lc_label_2</th>\n",
       "      <th>lc_label_3</th>\n",
       "      <th>lc_label_4</th>\n",
       "      <th>lc_label_5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "      <td>0.000199</td>\n",
       "      <td>0.007818</td>\n",
       "      <td>0.140270</td>\n",
       "      <td>0.162465</td>\n",
       "      <td>0.339045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000334</td>\n",
       "      <td>0.026691</td>\n",
       "      <td>0.213236</td>\n",
       "      <td>0.641323</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>0.010220</td>\n",
       "      <td>0.069199</td>\n",
       "      <td>0.825612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "      <td>0.000009</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.026951</td>\n",
       "      <td>0.145565</td>\n",
       "      <td>0.841762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "      <td>0.000229</td>\n",
       "      <td>0.000177</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.261229</td>\n",
       "      <td>0.917013</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  lc_label_1  lc_label_2  lc_label_3  lc_label_4  lc_label_5  \n",
       "0       4.155004    0.000199    0.007818    0.140270    0.162465    0.339045  \n",
       "1       4.446383    0.000016    0.000334    0.026691    0.213236    0.641323  \n",
       "2       4.744894    0.000197    0.001392    0.010220    0.069199    0.825612  \n",
       "3       4.616804    0.000009    0.000974    0.026951    0.145565    0.841762  \n",
       "4       4.726782    0.000229    0.000177    0.017185    0.261229    0.917013  "
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "models = [1, 2, 3, 4, 5]\n",
    "for model in models:\n",
    "    data_stacking = pd.merge(data_stacking, merge('train_lgbmc_lc_label', model), on = 'Id', how = 'left')\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "      <th>lc_label_1_x</th>\n",
       "      <th>lc_label_2</th>\n",
       "      <th>lc_label_3</th>\n",
       "      <th>lc_label_4</th>\n",
       "      <th>lc_label_5</th>\n",
       "      <th>lc_label_1_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "      <td>0.000199</td>\n",
       "      <td>0.007818</td>\n",
       "      <td>0.140270</td>\n",
       "      <td>0.162465</td>\n",
       "      <td>0.339045</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000334</td>\n",
       "      <td>0.026691</td>\n",
       "      <td>0.213236</td>\n",
       "      <td>0.641323</td>\n",
       "      <td>0.005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>0.010220</td>\n",
       "      <td>0.069199</td>\n",
       "      <td>0.825612</td>\n",
       "      <td>0.005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "      <td>0.000009</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.026951</td>\n",
       "      <td>0.145565</td>\n",
       "      <td>0.841762</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "      <td>0.000229</td>\n",
       "      <td>0.000177</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.261229</td>\n",
       "      <td>0.917013</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  lc_label_1_x  lc_label_2  lc_label_3  lc_label_4  \\\n",
       "0       4.155004      0.000199    0.007818    0.140270    0.162465   \n",
       "1       4.446383      0.000016    0.000334    0.026691    0.213236   \n",
       "2       4.744894      0.000197    0.001392    0.010220    0.069199   \n",
       "3       4.616804      0.000009    0.000974    0.026951    0.145565   \n",
       "4       4.726782      0.000229    0.000177    0.017185    0.261229   \n",
       "\n",
       "   lc_label_5  lc_label_1_y  \n",
       "0    0.339045         0.000  \n",
       "1    0.641323         0.005  \n",
       "2    0.825612         0.005  \n",
       "3    0.841762         0.000  \n",
       "4    0.917013         0.000  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_stacking = pd.merge(data_stacking, merge('train_clf_0_label_lc_label', 1), on = 'Id', how = 'left')\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "      <th>lc_label_1_x</th>\n",
       "      <th>lc_label_2_x</th>\n",
       "      <th>lc_label_3_x</th>\n",
       "      <th>lc_label_4_x</th>\n",
       "      <th>lc_label_5_x</th>\n",
       "      <th>...</th>\n",
       "      <th>lc_label_1_x</th>\n",
       "      <th>lc_label_2_y</th>\n",
       "      <th>lc_label_3_y</th>\n",
       "      <th>lc_label_4_y</th>\n",
       "      <th>lc_label_5_y</th>\n",
       "      <th>lc_label_1_y</th>\n",
       "      <th>lc_label_2</th>\n",
       "      <th>lc_label_3</th>\n",
       "      <th>lc_label_4</th>\n",
       "      <th>lc_label_5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "      <td>0.000199</td>\n",
       "      <td>0.007818</td>\n",
       "      <td>0.140270</td>\n",
       "      <td>0.162465</td>\n",
       "      <td>0.339045</td>\n",
       "      <td>...</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.035000</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.385000</td>\n",
       "      <td>0.420</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.040</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>0.3850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000334</td>\n",
       "      <td>0.026691</td>\n",
       "      <td>0.213236</td>\n",
       "      <td>0.641323</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.010000</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.342500</td>\n",
       "      <td>0.610</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.005</td>\n",
       "      <td>0.080</td>\n",
       "      <td>0.300000</td>\n",
       "      <td>0.5925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>0.010220</td>\n",
       "      <td>0.069199</td>\n",
       "      <td>0.825612</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000417</td>\n",
       "      <td>0.050</td>\n",
       "      <td>0.270000</td>\n",
       "      <td>0.705</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.010</td>\n",
       "      <td>0.035</td>\n",
       "      <td>0.290000</td>\n",
       "      <td>0.6700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "      <td>0.000009</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.026951</td>\n",
       "      <td>0.145565</td>\n",
       "      <td>0.841762</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.010000</td>\n",
       "      <td>0.055</td>\n",
       "      <td>0.340000</td>\n",
       "      <td>0.635</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.310000</td>\n",
       "      <td>0.6700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "      <td>0.000229</td>\n",
       "      <td>0.000177</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.261229</td>\n",
       "      <td>0.917013</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.272727</td>\n",
       "      <td>0.900</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.272727</td>\n",
       "      <td>0.9000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  lc_label_1_x  lc_label_2_x  lc_label_3_x  lc_label_4_x  \\\n",
       "0       4.155004      0.000199      0.007818      0.140270      0.162465   \n",
       "1       4.446383      0.000016      0.000334      0.026691      0.213236   \n",
       "2       4.744894      0.000197      0.001392      0.010220      0.069199   \n",
       "3       4.616804      0.000009      0.000974      0.026951      0.145565   \n",
       "4       4.726782      0.000229      0.000177      0.017185      0.261229   \n",
       "\n",
       "   lc_label_5_x     ...      lc_label_1_x  lc_label_2_y  lc_label_3_y  \\\n",
       "0      0.339045     ...              0.03      0.035000         0.220   \n",
       "1      0.641323     ...              0.00      0.010000         0.125   \n",
       "2      0.825612     ...              0.00      0.000417         0.050   \n",
       "3      0.841762     ...              0.00      0.010000         0.055   \n",
       "4      0.917013     ...              0.00      0.000000         0.000   \n",
       "\n",
       "   lc_label_4_y  lc_label_5_y  lc_label_1_y  lc_label_2  lc_label_3  \\\n",
       "0      0.385000         0.420          0.03       0.040       0.280   \n",
       "1      0.342500         0.610          0.00       0.005       0.080   \n",
       "2      0.270000         0.705          0.00       0.010       0.035   \n",
       "3      0.340000         0.635          0.00       0.000       0.090   \n",
       "4      0.272727         0.900          0.00       0.000       0.000   \n",
       "\n",
       "   lc_label_4  lc_label_5  \n",
       "0    0.375000      0.3850  \n",
       "1    0.300000      0.5925  \n",
       "2    0.290000      0.6700  \n",
       "3    0.310000      0.6700  \n",
       "4    0.272727      0.9000  \n",
       "\n",
       "[5 rows x 31 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "models = [1, 2, 3, 4, 5]\n",
    "clfs = [0, 1, 2, 3]\n",
    "for clf in clfs:\n",
    "    for model in models:\n",
    "        data_stacking = pd.merge(data_stacking, merge('train_clf_{}_label_lc_label'.format(clf), model), on = 'Id', how = 'left')\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "      <th>lc_label_1_x</th>\n",
       "      <th>lc_label_2_x</th>\n",
       "      <th>lc_label_3_x</th>\n",
       "      <th>lc_label_4_x</th>\n",
       "      <th>lc_label_5_x</th>\n",
       "      <th>...</th>\n",
       "      <th>lc_label_2_y</th>\n",
       "      <th>lc_label_3_y</th>\n",
       "      <th>lc_label_4_y</th>\n",
       "      <th>lc_label_5_y</th>\n",
       "      <th>lc_label_1_y</th>\n",
       "      <th>lc_label_2</th>\n",
       "      <th>lc_label_3</th>\n",
       "      <th>lc_label_4</th>\n",
       "      <th>lc_label_5</th>\n",
       "      <th>lstm_len_10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "      <td>0.000199</td>\n",
       "      <td>0.007818</td>\n",
       "      <td>0.140270</td>\n",
       "      <td>0.162465</td>\n",
       "      <td>0.339045</td>\n",
       "      <td>...</td>\n",
       "      <td>0.035000</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.385000</td>\n",
       "      <td>0.420</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.040</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>0.3850</td>\n",
       "      <td>4.543209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000334</td>\n",
       "      <td>0.026691</td>\n",
       "      <td>0.213236</td>\n",
       "      <td>0.641323</td>\n",
       "      <td>...</td>\n",
       "      <td>0.010000</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.342500</td>\n",
       "      <td>0.610</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.005</td>\n",
       "      <td>0.080</td>\n",
       "      <td>0.300000</td>\n",
       "      <td>0.5925</td>\n",
       "      <td>4.484506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>0.010220</td>\n",
       "      <td>0.069199</td>\n",
       "      <td>0.825612</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000417</td>\n",
       "      <td>0.050</td>\n",
       "      <td>0.270000</td>\n",
       "      <td>0.705</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.010</td>\n",
       "      <td>0.035</td>\n",
       "      <td>0.290000</td>\n",
       "      <td>0.6700</td>\n",
       "      <td>4.768332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "      <td>0.000009</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.026951</td>\n",
       "      <td>0.145565</td>\n",
       "      <td>0.841762</td>\n",
       "      <td>...</td>\n",
       "      <td>0.010000</td>\n",
       "      <td>0.055</td>\n",
       "      <td>0.340000</td>\n",
       "      <td>0.635</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.310000</td>\n",
       "      <td>0.6700</td>\n",
       "      <td>4.689859</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "      <td>0.000229</td>\n",
       "      <td>0.000177</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.261229</td>\n",
       "      <td>0.917013</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.272727</td>\n",
       "      <td>0.900</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.272727</td>\n",
       "      <td>0.9000</td>\n",
       "      <td>4.793519</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 32 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  lc_label_1_x  lc_label_2_x  lc_label_3_x  lc_label_4_x  \\\n",
       "0       4.155004      0.000199      0.007818      0.140270      0.162465   \n",
       "1       4.446383      0.000016      0.000334      0.026691      0.213236   \n",
       "2       4.744894      0.000197      0.001392      0.010220      0.069199   \n",
       "3       4.616804      0.000009      0.000974      0.026951      0.145565   \n",
       "4       4.726782      0.000229      0.000177      0.017185      0.261229   \n",
       "\n",
       "   lc_label_5_x     ...       lc_label_2_y  lc_label_3_y  lc_label_4_y  \\\n",
       "0      0.339045     ...           0.035000         0.220      0.385000   \n",
       "1      0.641323     ...           0.010000         0.125      0.342500   \n",
       "2      0.825612     ...           0.000417         0.050      0.270000   \n",
       "3      0.841762     ...           0.010000         0.055      0.340000   \n",
       "4      0.917013     ...           0.000000         0.000      0.272727   \n",
       "\n",
       "   lc_label_5_y  lc_label_1_y  lc_label_2  lc_label_3  lc_label_4  lc_label_5  \\\n",
       "0         0.420          0.03       0.040       0.280    0.375000      0.3850   \n",
       "1         0.610          0.00       0.005       0.080    0.300000      0.5925   \n",
       "2         0.705          0.00       0.010       0.035    0.290000      0.6700   \n",
       "3         0.635          0.00       0.000       0.090    0.310000      0.6700   \n",
       "4         0.900          0.00       0.000       0.000    0.272727      0.9000   \n",
       "\n",
       "   lstm_len_10  \n",
       "0     4.543209  \n",
       "1     4.484506  \n",
       "2     4.768332  \n",
       "3     4.689859  \n",
       "4     4.793519  \n",
       "\n",
       "[5 rows x 32 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_stacking = pd.merge(data_stacking, merge('train_lstm_len', 10), on = 'Id', how = 'left')\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "      <th>lgbm_model100</th>\n",
       "      <th>lgbm_model101</th>\n",
       "      <th>lgbm_model200</th>\n",
       "      <th>lc_label_1_x</th>\n",
       "      <th>lc_label_2_x</th>\n",
       "      <th>lc_label_3_x</th>\n",
       "      <th>lc_label_4_x</th>\n",
       "      <th>lc_label_5_x</th>\n",
       "      <th>...</th>\n",
       "      <th>lc_label_2</th>\n",
       "      <th>lc_label_3</th>\n",
       "      <th>lc_label_4</th>\n",
       "      <th>lc_label_5</th>\n",
       "      <th>lstm_len_10</th>\n",
       "      <th>ridge_doufu</th>\n",
       "      <th>ridge_noNormal</th>\n",
       "      <th>ridge_withNormal</th>\n",
       "      <th>ridge_wN_withMinMax</th>\n",
       "      <th>ridge_noN_withMinMax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "      <td>4.100287</td>\n",
       "      <td>4.282026</td>\n",
       "      <td>4.155004</td>\n",
       "      <td>0.000199</td>\n",
       "      <td>0.007818</td>\n",
       "      <td>0.140270</td>\n",
       "      <td>0.162465</td>\n",
       "      <td>0.339045</td>\n",
       "      <td>...</td>\n",
       "      <td>0.040</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>0.3850</td>\n",
       "      <td>4.543209</td>\n",
       "      <td>4.259031</td>\n",
       "      <td>4.106414</td>\n",
       "      <td>4.245187</td>\n",
       "      <td>4.245187</td>\n",
       "      <td>4.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "      <td>4.508073</td>\n",
       "      <td>4.493492</td>\n",
       "      <td>4.446383</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000334</td>\n",
       "      <td>0.026691</td>\n",
       "      <td>0.213236</td>\n",
       "      <td>0.641323</td>\n",
       "      <td>...</td>\n",
       "      <td>0.005</td>\n",
       "      <td>0.080</td>\n",
       "      <td>0.300000</td>\n",
       "      <td>0.5925</td>\n",
       "      <td>4.484506</td>\n",
       "      <td>4.484271</td>\n",
       "      <td>4.540086</td>\n",
       "      <td>4.502864</td>\n",
       "      <td>4.502864</td>\n",
       "      <td>4.521340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "      <td>4.693461</td>\n",
       "      <td>4.661598</td>\n",
       "      <td>4.744894</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>0.010220</td>\n",
       "      <td>0.069199</td>\n",
       "      <td>0.825612</td>\n",
       "      <td>...</td>\n",
       "      <td>0.010</td>\n",
       "      <td>0.035</td>\n",
       "      <td>0.290000</td>\n",
       "      <td>0.6700</td>\n",
       "      <td>4.768332</td>\n",
       "      <td>4.487762</td>\n",
       "      <td>4.687686</td>\n",
       "      <td>4.503818</td>\n",
       "      <td>4.503818</td>\n",
       "      <td>4.666100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "      <td>4.657754</td>\n",
       "      <td>4.582254</td>\n",
       "      <td>4.616804</td>\n",
       "      <td>0.000009</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.026951</td>\n",
       "      <td>0.145565</td>\n",
       "      <td>0.841762</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.310000</td>\n",
       "      <td>0.6700</td>\n",
       "      <td>4.689859</td>\n",
       "      <td>4.417822</td>\n",
       "      <td>4.677434</td>\n",
       "      <td>4.464252</td>\n",
       "      <td>4.464252</td>\n",
       "      <td>4.675244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "      <td>4.724437</td>\n",
       "      <td>4.724305</td>\n",
       "      <td>4.726782</td>\n",
       "      <td>0.000229</td>\n",
       "      <td>0.000177</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.261229</td>\n",
       "      <td>0.917013</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.272727</td>\n",
       "      <td>0.9000</td>\n",
       "      <td>4.793519</td>\n",
       "      <td>4.491485</td>\n",
       "      <td>4.859035</td>\n",
       "      <td>4.778371</td>\n",
       "      <td>4.778371</td>\n",
       "      <td>4.856289</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score  lgbm_model100  lgbm_model101  \\\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5       4.100287       4.282026   \n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4       4.508073       4.493492   \n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4       4.693461       4.661598   \n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5       4.657754       4.582254   \n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5       4.724437       4.724305   \n",
       "\n",
       "   lgbm_model200  lc_label_1_x  lc_label_2_x  lc_label_3_x  lc_label_4_x  \\\n",
       "0       4.155004      0.000199      0.007818      0.140270      0.162465   \n",
       "1       4.446383      0.000016      0.000334      0.026691      0.213236   \n",
       "2       4.744894      0.000197      0.001392      0.010220      0.069199   \n",
       "3       4.616804      0.000009      0.000974      0.026951      0.145565   \n",
       "4       4.726782      0.000229      0.000177      0.017185      0.261229   \n",
       "\n",
       "   lc_label_5_x          ...           lc_label_2  lc_label_3  lc_label_4  \\\n",
       "0      0.339045          ...                0.040       0.280    0.375000   \n",
       "1      0.641323          ...                0.005       0.080    0.300000   \n",
       "2      0.825612          ...                0.010       0.035    0.290000   \n",
       "3      0.841762          ...                0.000       0.090    0.310000   \n",
       "4      0.917013          ...                0.000       0.000    0.272727   \n",
       "\n",
       "   lc_label_5  lstm_len_10  ridge_doufu  ridge_noNormal  ridge_withNormal  \\\n",
       "0      0.3850     4.543209     4.259031        4.106414          4.245187   \n",
       "1      0.5925     4.484506     4.484271        4.540086          4.502864   \n",
       "2      0.6700     4.768332     4.487762        4.687686          4.503818   \n",
       "3      0.6700     4.689859     4.417822        4.677434          4.464252   \n",
       "4      0.9000     4.793519     4.491485        4.859035          4.778371   \n",
       "\n",
       "   ridge_wN_withMinMax  ridge_noN_withMinMax  \n",
       "0             4.245187              4.107143  \n",
       "1             4.502864              4.521340  \n",
       "2             4.503818              4.666100  \n",
       "3             4.464252              4.675244  \n",
       "4             4.778371              4.856289  \n",
       "\n",
       "[5 rows x 37 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ridge\n",
    "data_stacking = pd.merge(data_stacking, merge('train_ridge', 'doufu'), on = 'Id', how = 'left')\n",
    "\n",
    "data_stacking = pd.merge(data_stacking, merge('train_ridge', '1'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_ridge', '2'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_ridge', '3'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_ridge', '4'), on = 'Id', how = 'left')\n",
    "\n",
    "data_stacking = pd.merge(data_stacking, merge('train_lasso', '1'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_lasso', '2'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_lasso', '3'), on = 'Id', how = 'left')\n",
    "data_stacking = pd.merge(data_stacking, merge('train_lasso', '4'), on = 'Id', how = 'left')\n",
    "\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "data_stacking.to_csv('../input/data_stacking.csv', index = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
